package com.beyond.trace.domain.vo.Knowledge;

import com.beyond.trace.domain.knowledgebase.CropKnowledge;
import com.beyond.trace.domain.knowledgebase.KnowledgeBase;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
 * @ClassName: CropKnowledgeBase
 * @author: z越
 * @date: 2024/2/20  13:58
 * @description
 */
@Data
@ApiModel("作物知识库")
public class CropKnowledgeBase {
    @ApiModelProperty("主键id(新增时不填，修改时必填)")
    private Long id;
    @Excel(name = "作物名称",prompt = "必填")
    @ApiModelProperty("作物名称")
    @NotBlank(message = "作物名称不能为null")
    private String cropName;
    @Excel(name = "作物简介")
    @ApiModelProperty("作物简介")
    private String blurb;
    @ApiModelProperty("地理分布")
    @Excel(name = "地理分布")
    private String distribution;
    @Excel(name = "形态特征")
    @ApiModelProperty("形态特征")
    private String formFeature;
    @Excel(name = "生长习性")
    @ApiModelProperty("生长习性")
    private String growthHabit;
    @Excel(name = "品种分类")
    @ApiModelProperty("品种分类")
    private String breedType;
    @Excel(name = "栽培技术")
    @ApiModelProperty("栽培技术")
    private String cultivateSkill;

    @Excel(name = "图片1")
    @ApiModelProperty("图片1")
    private String picture1;
    @Excel(name = "图片2")
    @ApiModelProperty("图片2")
    private String picture2;
    @Excel(name = "图片3")
    @ApiModelProperty("图片3")
    private String picture3;

    @ApiModelProperty("图片地址（界面新增时或修改时使用，多个用‘，’隔开）")
    private String pictures;

    public KnowledgeBase toPo(){
        KnowledgeBase po = new KnowledgeBase();
        po.setCreateTime(new Date());
        po.setName(this.cropName);
        po.setProfile(this.blurb);
        po.setFormFeature(this.formFeature);
        po.setPictures(this.pictures);

        if (StringUtils.isNotEmpty(this.picture1) || StringUtils.isNotEmpty(this.picture2) || StringUtils.isNotEmpty(this.picture3)){
            po.setPictures(this.picture1 + "," + this.picture2 + "," + this.picture3);
        }
        po.setType("crop");
        po.setCreateBy(SecurityUtils.getUsername());
        CropKnowledge extend = new CropKnowledge();
        if (StringUtils.isNotEmpty(this.distribution)){
            extend.setDistribution(this.distribution);
        }
        if (StringUtils.isNotEmpty(this.growthHabit)){
            extend.setGrowthHabit(this.growthHabit);
        }
        if (StringUtils.isNotEmpty(this.breedType)){
            extend.setBreedType(this.breedType);
        }
        if (StringUtils.isNotEmpty(this.cultivateSkill)){
            extend.setCultivateSkill(this.cultivateSkill);
        }
        po.setExtend(extend);
        return po;
    }
}
